package com.elite;

import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.Date;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.*;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.SOAPHeaderElement;

import cn.com.wfsms.SmsServiceClient;

import com.baosight.smssvr.model.SmsBatchModel;
import com.baosight.smssvr.model.SmsModel;

public class SendSMSTest
{
	
    String certSerialNumber;
    String appNumber;
    String exNumber;
    String phone;
    String msg;
    int timeFlag;
    long smsTime;
    String msgFlag;

    public void RemoteSendSMSTest()
    {
        certSerialNumber = "0000000000";
        appNumber = "111111111";
        exNumber = "911";
        phone = "13636445902";
        msg = "WebServices短信测试";
        timeFlag = 0;
        smsTime = System.currentTimeMillis();
        msgFlag = "backup";
    }


    public void testXML()
    {
		SmsBatchModel smsbat = new SmsBatchModel();
			//允许重发次数，必输项，不赋值默认0
		smsbat.setAllow_retry_cnt(new Integer(1)); 
			//启动发送时间，必输项
		smsbat.setCaller("WEB");
		Calendar cld1 = Calendar.getInstance();
		//date1类型可以为java.util.Date或java.sql.Timestamp
		cld1.setTime(new Date());
		smsbat.setBegin_send_date(cld1); 
			//最晚发送时间，可不输
//		Calendar cld2 = Calendar.getInstance();
//		//date2类型可以为java.util.Date或java.sql.Timestamp
//		cld1.setTime(new Date()); 
//		smsbat.setEnd_send_date(cld2); 
			//来源业务类别，必输项，必须是短信业务类别表中已维护的
		smsbat.setBiz_type("g");
			//是否邮件反馈结果，1是，0否，必输项
		smsbat.setIs_mail("0");
			//发送人邮箱，是否邮件反馈结果=“是”时必输
		smsbat.setSend_user_email("aaa@163.com");
			//发送人姓名，必输项
		smsbat.setSend_user_name("张三");
			//发送人ID，必输项
		smsbat.setSend_user("1234");
			//发送部门ID，必输项
		smsbat.setSend_depts("01");
			//发送部门名称，必输项
		smsbat.setSend_depts_name("XXX业务中心");
			//备注，标识信息
		smsbat.setFremarks("备注信息");
			//短信数量
		int a = 1; 
			//创建短信数组
		SmsModel[] smsarr = new SmsModel[a];
		for(int i=0;i<a;i++)
		{
				//短信对象
			SmsModel sms = new SmsModel();
				//手机号，必输项				
			sms.setMp("13636445902");
//短信内容，必输项
			sms.setContent("new cc or dd");
				//接收者ID，必输项
			sms.setRcv_id("222222");
				//接收者类别，必输项，'EMP' 雇员，'SUPL' 供应商，
//'LD' 客户联系人，'COMM' 一般人员
			sms.setRcv_type("EMP");
				//接受者所属客户组编号
			sms.setComp_grp_code("11");
				//接受者所属客户编号
			sms.setCompany_no("11");
				//接受者所属业务部ID
			sms.setDept_no("02");
				//放入短信数组
			smsarr[i] = sms;
		} 
			//创建短信数组包装类对象
//		ArrayOfSmsModel smslst = new ArrayOfSmsModel();
//			//将短信数组放入包装类对象
//		smslst.setSmsModel(smsarr); 
//			//将短信数组包装类对象放入短信任务对象
		
		smsbat.setSmslist(smsarr); 
			//调用接口发送
//		long batno = sender.sendSmsBatch(smsbat);
		
        SmsServiceClient client = new SmsServiceClient();
		String endpoint = "http://172.16.96.101/WfShortMsgService/services/SmsService";
		try{
			Service service = new Service();
			Call call = null;
	        call = (Call) service.createCall();
	        call.setOperationName(new QName("http://smssvr.baosight.com/ISmsService","sendSmsBatch"));
	        call.setTargetEndpointAddress(new java.net.URL(endpoint));
	        call.setReturnType(XMLType.XSD_LONG); //设置返回值类型
	        QName qn = new QName("http://model.smssvr.baosight.com","SmsBatchModel");
//	        call.registerTypeMapping(SmsBatchModel.class, qn, new BeanSerializerFactory(SmsBatchModel.class, qn), new BeanDeserializerFactory(SmsBatchModel.class, qn));
			call.addParameter("in0",XMLType.XSD_STRING,ParameterMode.IN);
			call.addParameter("in1",qn,ParameterMode.IN);
	        Object rspXML =  call.invoke(new Object[]{"mrzhuyqRR",smsbat});
	        System.out.println("return value is " + rspXML);
		}catch(Exception e){
			e.printStackTrace();
		}
    }

    public static void main(String args[]) throws ServiceException, MalformedURLException, RemoteException
    {
//        SendSMSTest test = new SendSMSTest();
//        test.testXML();
    	String endpoint="http://192.168.2.126:8080/EliteOrderService/services/IOrder";
		Service service = new Service();
		Call call = null;
        call = (Call) service.createCall();
        call.setOperationName(new QName("http://order.elite.com","getFirstCategory"));
        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setReturnType(XMLType.XSD_STRING); //设置返回值类型
        Object rspXML =  call.invoke(new Object[]{});
        System.out.println("return value is " + rspXML);
        
        
        
    }

}
